package com.atguigu.day08;

import org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend;
import org.apache.flink.contrib.streaming.state.RocksDBStateBackend;
import org.apache.flink.runtime.state.CheckpointStorage;
import org.apache.flink.runtime.state.filesystem.FsStateBackend;
import org.apache.flink.runtime.state.hashmap.HashMapStateBackend;
import org.apache.flink.runtime.state.memory.MemoryStateBackend;
import org.apache.flink.runtime.state.storage.FileSystemCheckpointStorage;
import org.apache.flink.runtime.state.storage.JobManagerCheckpointStorage;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.io.IOException;

public class Flink02_StateBackend {
    public static void main(String[] args) throws IOException {
        //1.获取流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //老版本写法
        //内存
        env.setStateBackend(new MemoryStateBackend());

        //文件
        env.setStateBackend(new FsStateBackend("hdfs://hadoop102:8020/flink/ck"));

        //RocksDb
        env.setStateBackend(new RocksDBStateBackend("hdfs://hadoop102:8020/flink/rocksBb"));


        //1.13版本之后写法

        //内存
        env.setStateBackend(new HashMapStateBackend());
        //ck
        env.getCheckpointConfig().setCheckpointStorage(new JobManagerCheckpointStorage());

        //文件
        env.setStateBackend(new HashMapStateBackend());
        //ck
        env.getCheckpointConfig().setCheckpointStorage(new FileSystemCheckpointStorage("hdfs://hadoop102:8020/flink/ck"));


        //rocksDb
        env.setStateBackend(new EmbeddedRocksDBStateBackend());
        //CK
        env.getCheckpointConfig().setCheckpointStorage(new FileSystemCheckpointStorage("hdfs://hadoop102:8020/flink/ck/rocksDb"));

        //不对齐Barrier
        env.getCheckpointConfig().enableUnalignedCheckpoints();

    }
}
